package com.example.mobile203zlw20216061300616;

import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import androidx.appcompat.app.AppCompatActivity;

import java.util.ArrayList;
import java.util.List;

public class MainActivity2 extends AppCompatActivity {
    private EditText edname;
    private EditText edskill;
    private EditText edmaney;
    private Button buquxiao;
    private Button buquedin;
    mySQList mySQList;
    SQLiteDatabase database;
    private List<Student> list=new ArrayList<>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        initView();
    }
    public void button(View view) {
        switch (view.getId()){
            case R.id.buquedin:
                mySQList=new mySQList(this,"staff.db",null,1);
                database=mySQList.getWritableDatabase();
                String tename = edname.getText().toString();
                String teskill=edskill.getText().toString();
                int temaney= Integer.parseInt(edmaney.getText().toString());
                ContentValues values=new ContentValues();
                values.put("name",tename);
                values.put("skill",teskill);
                values.put("maney",temaney);
                database.insert("student",null,values);
                database.close();
                break;
            case R.id.buquxiao:
                Intent intent = new Intent(MainActivity2.this, MainActivity.class);
                startActivity(intent);
                break;
        }
    }

    private void initView() {
        edname = (EditText) findViewById(R.id.edname);
        edskill = (EditText) findViewById(R.id.edskill);
        edmaney = (EditText) findViewById(R.id.edmaney);
        buquxiao = (Button) findViewById(R.id.buquxiao);
        buquedin = (Button) findViewById(R.id.buquedin);
    }
}